package file

import (
	"io"
	"mime/multipart"
	"os"
	"path"
)

func GetSize(f multipart.File) (int, error) {
	content, err := io.ReadAll(f)
	return len(content), err
}

func GetExt(fileName string) string {
	return path.Ext(fileName)
}

func CheckNotExist(src string) bool {
	_, err := os.Stat(src)
	return os.IsNotExist(err)
}

func CheckPermission(src string) bool {
	_, err := os.Stat(src)
	return os.IsPermission(err)
}

func IsNotExistMkDir(src string) error {
	if exist := CheckNotExist(src); exist == true {
		if err := os.MkdirAll(src, os.ModePerm); err != nil {
			return err
		}
	}
}

func MkDir(dir string) error {
	return os.MkdirAll(dir, os.ModePerm)
}
